import {
    otherRouter,
    appRouter,
    factoryRouter,
    dealerRouter,
    terminalRouter
} from '@/router/router';
import Cookies from 'js-cookie';
const app = {
    state: {
        menuList: [],
        routers: [
            otherRouter,
            ...appRouter,
            ...factoryRouter,
            ...dealerRouter,
            ...terminalRouter
        ]
    },
    mutations: {
        updateMenulist (state) {
            // 根据不同角色加载不同菜单
            let role = Cookies.get('role');
            if ('工厂' === role) {
                state.menuList = factoryRouter;
            }
            if ('经销商' === role) {
                state.menuList = dealerRouter;
            }
            if ('终端门店' === role) {
                state.menuList = terminalRouter;
            }
        },

        clearMenuList (state) {
            state.menuList = [];
        }
    }
};

export default app;